package com.emm.yixun.website.controller.system;

import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.emm.yixun.common.model.Area;
import com.emm.yixun.common.model.dto.AreaDto;
import com.emm.yixun.common.response.ResponseList;
import com.emm.yixun.system.service.AreaServiceFacade;
import com.emm.yixun.website.common.ajax.AjaxRes;
import com.emm.yixun.website.controller.base.BaseController;

@Controller
@RequestMapping("/system/area/")
public class AreaController extends BaseController<Area>{
	
	@Autowired
	private AreaServiceFacade areaServiceFacade;
	
	@RequestMapping(value="findAreaByParentId", method=RequestMethod.POST)
	@ResponseBody
	public AjaxRes findAreaByParentId(Long parentId){
		AjaxRes ar=getAjaxRes();
		try {
			AreaDto dto=new AreaDto();
			dto.setParentId(parentId);
			ResponseList<Area> responseList=areaServiceFacade.findByDto(dto);
			if(responseList.isSuccess() && null!=responseList.getEntity()){
				ar.setSucceed(responseList.getEntity());
			}else{
				ar.setSucceed(new ArrayList<Area>());
			}
		} catch (Exception e) {
			logger.error(e.toString(),e);
			ar.setSucceed(new ArrayList<Area>());
		}
		
		return ar;
	}
}
